package com.lzw.bluetoothpractice.Adapters;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.lzw.bluetoothpractice.Activitys.HealthyDetailActivity;
import com.lzw.bluetoothpractice.Models.Article;
import com.lzw.bluetoothpractice.Models.Collect;
import com.lzw.bluetoothpractice.R;

import java.util.List;

public class MyCollectionAdapter extends RecyclerView.Adapter<MyCollectionAdapter.ViewHolder> {


    View itemView;
    Context mcontext;
    List<Collect> collectList;

    public MyCollectionAdapter(Context mcontext, List<Collect> collectList) {
        this.mcontext = mcontext;
        this.collectList=collectList;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        itemView= LayoutInflater.from(mcontext).inflate(R.layout.healthy_message,parent,false);

        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Collect collect=collectList.get(position);

        Glide.with(mcontext).load(collect.getUrl()).into(holder.imageHealth);
        holder.textHealth.setText(collect.getTitle());
        holder.dateHealth.setText(collect.getCreatedAt());

        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                Bundle bundle = new Bundle();
                // bundle.putSerializable("conversation", conversationEntrance);
                bundle.putString("articleID", collect.getArticleID());

                intent.setClass(mcontext, HealthyDetailActivity.class);
                if (bundle != null) {
                    intent.putExtras(bundle);
                }
                mcontext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return collectList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        View view;
        ImageView imageHealth;
        TextView  textHealth;
        TextView  dateHealth;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            view=itemView;
            imageHealth=view.findViewById(R.id.imageHealth);
            textHealth=view.findViewById(R.id.textHealth);
            dateHealth=view.findViewById(R.id.dateHealth);

        }
    }

}
